﻿using System.Drawing;
using System.Windows.Forms;

namespace Aspects.Custom
{
    public class InformationLabel : Control
    {
        private Color _leftColor = SystemColors.Control;
        private Color _rightColor = SystemColors.Info;
        private string _caption;
        public InformationLabel()
        {
            this.Size = new Size(50, 15);
        }
        public string Caption
        {
            get
            {
                return _caption;
            }
            set
            {
                _caption = value;
                Invalidate();
            }
        }
        public override string Text
        {
            get
            {
                return base.Text;
            }
            set
            {
                base.Text = value;
                Invalidate();
            }
        }
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            var BoldFont = new Font(Font, FontStyle.Bold);
            Size CaptionSize = TextRenderer.MeasureText(Caption, BoldFont);
            var SplitPoint = new Point(CaptionSize.Width, 0);
            var leftBrush = new SolidBrush(_leftColor);
            var rightBrush = new SolidBrush(_rightColor);
            e.Graphics.DrawRectangle(Pens.Black, 0, 0, Width - 1, Height - 1);
            e.Graphics.FillRectangle(leftBrush, 1, 1, SplitPoint.X - 1, this.Height - 2);
            e.Graphics.FillRectangle(rightBrush, SplitPoint.X + 1, 1, Width - CaptionSize.Width - 2, this.Height - 2);
            e.Graphics.DrawLine(Pens.Black, SplitPoint.X, SplitPoint.Y, SplitPoint.X, this.Height);
            e.Graphics.DrawString(Caption, BoldFont, Brushes.Black, 0.0f, 0.0f);
            e.Graphics.DrawString(Text, Font, Brushes.Black, SplitPoint.X + 1, 0.0f);
        }
    }
}